package com.zzy.mccjt.controller.check;

import com.zzy.mccjt.retelimiter.LimiterType;
import com.zzy.mccjt.retelimiter.RateLimiter;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

/**
 * @program: mccjt-cloud
 * @description:
 * @author: zhouyang.zheng
 * @create: 2022-07-01 17:41
 **/
@Api(value = "测试集成工具类是否成功", tags = "测试集成工具类是否成功")
@RestController
@RequestMapping("/api/v1/test_integrate")
public class testIntegrateUtilController {

    @Autowired
    private RedisTemplate redisTemplate;

    @ApiOperation("测试redis是否集成成功")
    @PostMapping("/testRedis")
    public Boolean test() {
        redisTemplate.opsForValue().set("test", "test", 1000, TimeUnit.SECONDS);
        return true;
    }


    /**
     * 启动项目，在一秒内连续调用本接口三次以上即可验证是否成功
     * @return
     */
    @ApiOperation("测试retelimiter是否集成成功")
    @PostMapping("/test/retelimiter")
    @RateLimiter(type = LimiterType.KEY, key = "#key", burstCapacity = 3)
    public Boolean testRetelimiter(String key) {
        return true;
    }
}
